package servlet;

import java.io.*;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;




/**
 * Servlet implementation class CompanyServlet
 */
@WebServlet(urlPatterns = { "/Note", "/note", "/NoteServlet", "/noteServlet" }, initParams = { @WebInitParam(name = "mode", value = "") })
public class NoteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * Default constructor.
	 */
	public NoteServlet() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/xml; charset=UTF-8");
	
		String mode = request.getParameter("mode");
		String id = request.getParameter("id");
		String text = request.getParameter("text");
		text = new String(text.getBytes("ISO-8859-1"), "UTF-8");
		String pos_x = request.getParameter("x");
		String pos_y = request.getParameter("y");
		String width = request.getParameter("width");
		String height = request.getParameter("height");
		
		System.out.print("id= "+id);
		System.out.print("        mode= "+mode);
		
		if (mode.equalsIgnoreCase("create")) {
			System.out.print("        text= "+text);
			System.out.print("        pos x= "+pos_x);
			System.out.print("        pos y= "+pos_y);
			System.out.print("        width= "+width);
			System.out.println("        height= "+height);
		}
		
		if (mode.equalsIgnoreCase("edit")) {
			System.out.print("        new text= "+text);
			System.out.print("        pos x= "+pos_x);
			System.out.print("        pos y= "+pos_y);
			System.out.print("        width= "+width);
			System.out.println("        height= "+height);
		
		}
		
		if (mode.equalsIgnoreCase("delete")) {
			System.out.print("        text= "+text);
			System.out.print("        pos x= "+pos_x);
			System.out.print("        pos y= "+pos_y);
			System.out.print("        width= "+width);
			System.out.println("        height= "+height);
		
		}
		
		if (mode.equalsIgnoreCase("move")) {
			System.out.print("        text= "+text);
			System.out.print("        new pos x= "+pos_x);
			System.out.print("        new pos y= "+pos_y);
			System.out.print("        width= "+width);
			System.out.println("        height= "+height);
		}
		
		if (mode.equalsIgnoreCase("resize")) {
			System.out.print("        text= "+text);
			System.out.print("        pos x= "+pos_x);
			System.out.print("        pos y= "+pos_y);
			System.out.print("        new width= "+width);
			System.out.println("        new height= "+height);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		
		// TODO read from URL param
		
		
		
	}
}